﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace STAR.Spring.Framework.Module
{
    public  class CustomResponse : ICustomResponse
    {
        public ReturnDataType requestType { get; set; }
        public CustomResponse()
        {
        }
        public virtual bool BeforeReadData(string requestName, params object[] parms)
        {
            return true;
        }

        public virtual DataTable ReadData(string requestName, params object[] parms)
        {
            return DBProcess.GetDataTable(requestName, parms);
        }

        public virtual bool AfterReadData(DataTable dt)
        {
            return true;
        }

        public virtual bool BeforeCreateResult(DataTable dt)
        {
            return true;
        }

        public virtual dynamic CreateResult(DataTable dt)
        {
            dynamic mainData = null;

            switch (requestType)
            {
                case ReturnDataType.单值:
                    if (dt.Rows.Count > 0)
                    {
                        return mainData = dt.Rows[0][0].ToString();
                    }
                    break;
                case ReturnDataType.对象:
                    mainData = Founder.PKURG.Common.Core.CustomMapping.GetObject(dt);
                    break;
                case ReturnDataType.列表:
                    mainData = Founder.PKURG.Common.Core.CustomMapping.GetList(dt);
                    break;
                default:
                    break;
            }
            return mainData;
        }


        public virtual bool AfterCreateResult(dynamic result)
        {
            return true;
        }

        public virtual dynamic CustomProcess(string requestName, params object[] parms)
        {
            throw new NotImplementedException();
        }
    }
}
